
OrgList = new Pearlsen.BaseList({
	gridId:'orgGrid',
	advSearchId:'advSearchWin',
	module:'部门',
	modulePath:'/pages/sysmgr/org/',
	moduleName:'Org',
	idProperty:'ORG_ID',
	nameProperty:'ORG_FULL_NAME',
	dataSetHandler:'OrgDataSetHandler',
	queryHandler:'OrgQueryHandler',
	//重写
	add:function(){
		var tree = Ext.getCmp("orgTree");
		var node = tree.getSelectionModel().getSelection();
		if( node && node.length > 0 ){
			var url = this.getAddUrl();
			url = url+"?parentId={0}";
			url = url.format(node[0].data['id']);
			var tabId = this.createTabId("add");
			parent.MainTab.addTab(tabId,"新增"+this.module,url);
		}else{
			Pearlsen.Utils.showInfoMsg('请先选中父级部门');
		}
	},
	orgUp:function(){
		var me = OrgList;
		var record = me.getSelectedOne();
		if(record==null){
			return ;
		}
		var orgID =record.data[me.idProperty];
		
    	var dataSet = new DataSet(this.dataSetHandler,"_up_dataset");
    	dataSet.setHandlerMethod("orgUp");
    	dataSet.newRecord();
    	dataSet.setValue("orgID",orgID);
    	dataSet.execute(function(result){
    		if(result.getStatus()=="200"){
    			var node =Ext.getCmp("orgTree").getSelectionModel().getLastSelected();
    			me.loadGridByNodeId(node.data["id"]);
    			return;
    		}else{
    			Pearlsen.Utils.showErrorMsg(result.message);
    			return ;
    		}
    	});	
	},
	orgDown:function(){
		var me = OrgList;
		var record = me.getSelectedOne();
		if(record==null){
			return ;
		}
		var orgID =record.data[me.idProperty];
    	var dataSet = new DataSet(this.dataSetHandler,"_up_dataset");
    	dataSet.setHandlerMethod("orgDown");
    	dataSet.newRecord();
    	dataSet.setValue("orgID",orgID);
    	dataSet.execute(function(result){
    		if(result.getStatus()=="200"){
    			var node =Ext.getCmp("orgTree").getSelectionModel().getLastSelected();
    			me.loadGridByNodeId(node.data["id"]);
    			return;
    		}else{
    			Pearlsen.Utils.showErrorMsg(result.message);
    			return ;
    		}
    	});	
		
	},
	itemclick:function(tree,model){
		var me = OrgList;
		me.loadGridByNodeId(model.get("id"));
	},
	loadGridByNodeId:function(nodeId){
		var me = OrgList;
  		var store=me.getGrid().getStore();
  		var condition=new Condition("node",nodeId);
  		store.clearCondition();
  		store.addCondition(condition);
  		store.load();
	},
	
	renderMenutype:function(value){
        var val = "";
        switch (value) {
            case "1":
                val = "<span style='color:green;'>菜单</span>";
                break;
            case "0":
                val = "<span style='color:blue;'>按钮</span>";
                break;
        }
        return val;
	},
	statusRender:function(value){
        var val = "";
        switch (value) {
            case "1":
                val = "<span style='color:green;'>启用</span>";
                break;
            case "0":
                val = "<span style='color:red;'>停用</span>";
                break;
        }
        return val;
	}
});
